﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using YFurion.Entities;

namespace UpperComputer.Core.Entities
{
    public class BaseRole : FullEntity, IEntityTypeBuilder<BaseRole>
    {
        public BaseRole()
        {
            BaseRoleUser = new HashSet<BaseRoleUser>();
        }

        public string Code { get; set; }

        public string DisplayName { get; set; }
    
        public string Description { get; set; }

        public virtual ICollection<BaseRoleUser> BaseRoleUser { get; set; }

        public void Configure(EntityTypeBuilder<BaseRole> entity, DbContext dbContext, Type dbContextLocator)
        {
            entity.HasIndex(e => e.Code, "UQ__BaseRole")
                    .IsUnique();

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("编号");

            entity.Property(e => e.Code)
                .IsRequired()
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("编码");

            entity.Property(e => e.CreationTime).HasComment("创建时间");

            entity.Property(e => e.CreatorUserId)
                .HasComment("创建者编号");

            entity.Property(e => e.DeleterUserId)
                .HasComment("删除者编号");

            entity.Property(e => e.DeletionTime).HasComment("删除时间");

            entity.Property(e => e.Description)
                .HasMaxLength(255)
                .HasComment("描述");

            entity.Property(e => e.DisplayName)
                .IsRequired()
                .HasMaxLength(50)
                .HasComment("显示名称");

            entity.Property(e => e.IsDeleted).HasComment("是否删除");

            entity.Property(e => e.LastModificationTime).HasComment("最后一次修改时间");

            entity.Property(e => e.LastModifierUserId)
                .HasComment("最后一次修改者编号");
        }
    }
}

